package cn.lili.xiaoran.service.impl;

import cn.lili.xiaoran.entity.LiQuestionsCollection;
import cn.lili.xiaoran.mapper.LiQuestionsCollectionMapper;
import cn.lili.xiaoran.service.LiQuestionsCollectionService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 收藏表(LiQuestionsCollection)表服务实现类
 *
 * @author makejava
 * @since 2022-08-14 22:05:25
 */
@Service("liQuestionsCollectionService")
public class LiQuestionsCollectionServiceImpl extends ServiceImpl<LiQuestionsCollectionMapper, LiQuestionsCollection> implements LiQuestionsCollectionService {
    @Resource
    private LiQuestionsCollectionMapper liQuestionsCollectionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public LiQuestionsCollection queryById(Integer id) {
        return this.liQuestionsCollectionDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param liQuestionsCollection 筛选条件
     * @param pageRequest           分页对象
     * @return 查询结果
     */
    @Override
    public Page<LiQuestionsCollection> queryByPage(LiQuestionsCollection liQuestionsCollection, PageRequest pageRequest) {
        long total = this.liQuestionsCollectionDao.count(liQuestionsCollection);
        return new PageImpl<>(this.liQuestionsCollectionDao.queryAllByLimit(liQuestionsCollection, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param liQuestionsCollection 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestionsCollection insert(LiQuestionsCollection liQuestionsCollection) {
        this.liQuestionsCollectionDao.insert(liQuestionsCollection);
        return liQuestionsCollection;
    }

    /**
     * 修改数据
     *
     * @param liQuestionsCollection 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestionsCollection update(LiQuestionsCollection liQuestionsCollection) {
        this.liQuestionsCollectionDao.update(liQuestionsCollection);
        return this.queryById(liQuestionsCollection.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.liQuestionsCollectionDao.deleteById(id) > 0;
    }
}
